#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QPushButton>
#include <QFontDatabase>
#include <QMenu>
#include <QSystemTrayIcon>

#include <QMediaPlayer>
#include <QMediaPlaylist>
#ifdef USE_FFMPEG
#include "qffmpegobject.h"
#endif

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QWidget
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void sltQuit();

    void slot_durationChanged(qint64 duration);
    void slot_positionChanged(qint64 position);
    void slot_currentMediaIndexChanged(int index);
    void sltMenuTriggerd(QAction *action);
    void sltPlaymodeTriggerd(QAction *action);
    void onActivated(QSystemTrayIcon::ActivationReason reason);
    void on_btnDir_clicked();
    void slot_musicListClicked(int index);

private:
    void initMenu();
    void initTrayIcon();
    void initicon();
    void initPlayer();
    void scanMusics(const QString &musicPath);

    void showHidePlayList();
    void loadsettings();
    void setIcon(QPushButton *btn, QChar iconCode, uint dwSize);
    QString changeTime(qint64 secs);

private:
    Ui::MainWindow *ui;
    QMenu *m_menu;
    QSystemTrayIcon *m_sysTrayicon;
    QFont m_iconfont;

    QMediaPlayer *m_player;
    QMediaPlaylist *m_playlist;
    QStringList     m_musics;
#ifdef USE_FFMPEG
    QFFmpegObject   *m_ffmpeg;
#endif

    QString         m_strMusicPath;
protected:
    bool m_isPressed;
    QPoint m_startPos;
    void mousePressEvent(QMouseEvent *e) override;
    void mouseMoveEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *) override;
};
#endif // MAINWINDOW_H
